function loadLoginMain() {
  $('#main').html(template('t_loginMain'))

  $('input').keydown(function() {
    $('.warning1').empty()
    $('.warning2').empty()
  })

  if (localStorage.username) {
    $('.loginCenter .username').val(localStorage.username)
    $('.loginCenter .password').val(localStorage.password)
  }

  $('.loginCenter').css('display', 'block')
  $('.registerCenter').css('display', 'none')

  $(".registerPanel").click(function() {
    $('.loginCenter').css('display', 'none')
    $('.registerCenter').css('display', 'block')
    $('input').val('')
  })

  $(".cancel").click(function() {
    $('.loginCenter').css('display', 'block')
    $('.registerCenter').css('display', 'none')
    $('input').val('')
  })

  $(".login").click(function() {
    if ($('.loginCenter .username').val() === '') {
      $('.warning1').html('*用户名不能为空')
      return
    }
    if ($('.loginCenter .password').val() === '') {
      $('.warning1').html('*密码不能为空')
      return
    }
    var username = Trim($('.loginCenter .username').val())
    localStorage.username = username
    localStorage.password = Trim($('.loginCenter .password').val())
    var password = base32.encode(Trim($('.loginCenter .password').val()))
      //用户登录
    $.get(UserClientIp + '/userLogin', {
      username: username,
      password: password
    }, function(res) {
      console.log(res)
      if (res.error === 0) {
        client.init(ClientIp, function() {
          request.playerLogin(username, password)
        })
      } else {
        $('.warning1').html('*用户名不存在或密码不正确')
      }
    }, 'json').error(function(xhr, errorText,errorType){
      $('.warning1').html('*服务器连接失败,请检查网络是否连接')
    })
  })

  $(".register").click(function() {
    if (!localStorage.register) {
      localStorage.register = 0
      localStorage.registerTime = new Date().getTime()
    }
    if (new Date().getTime() - localStorage.registerTime > 432000000) {
      localStorage.registerTime = new Date().getTime()
      localStorage.register = 0
    }
    if (localStorage.register > 2) {
      $('.warning2').html('*一周一台手机只能注册2个账号')
      return
    }
    if (!/^([a-z]|[A-Z]|[0-9]){3,16}$/.test($('.registerCenter .username').val())) {
      $('.warning2').html('*用户名是3-16位的字母或数字')
      return
    }
    if (!/^([a-z]|[A-Z]|[0-9]){3,16}$/.test($('.registerCenter .password').val())) {
      $('.warning2').html('*密码是6-16位的字母或数字')
      return
    }
    var username = Trim($('.registerCenter .username').val())
    var password = base32.encode(Trim($('.registerCenter .password').val()))
    //用户注册
    $.get(UserClientIp + '/createUser', {
      username: username,
      password: password
    }, function(res) {
      console.log(res)
      if (res.error === 0) {
        $('.warning1').html('*注册成功')
        $('.loginCenter').css('display', 'block')
        $('.registerCenter').css('display', 'none')
        $('.loginCenter .username').val(username)
        $('.loginCenter .password').val(Trim($('.registerCenter .password').val()))
        localStorage.register += 1
      } else {
        $('.warning2').html('*用户名已经存在')
      }
    }, 'json').error(function(xhr, errorText,errorType){
      $('.warning2').html('*服务器连接失败,请检查网络是否连接')
    })
  })
}
